package com.wnx.job.modules.pms.controller;

import com.wnx.job.common.api.Const;
import com.wnx.job.common.api.PageResult;
import com.wnx.job.common.api.QueryPageBean;
import com.wnx.job.common.api.ResultData;
import com.wnx.job.modules.jms.model.JmsCompany;
import com.wnx.job.modules.jms.service.JmsCompanyService;
import com.wnx.job.modules.pms.model.PmsPass;
import com.wnx.job.modules.pms.service.PmsPassService;
import com.wnx.job.modules.rms.dto.PassParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.security.Principal;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wangnaixing
 * @since 2021-12-17
 */
@Slf4j
@RestController
@RequestMapping("/pms/pmsPass")
@Api(tags = "PassControllerByStudent",description = "简历通过信息管理")
public class PmsPassController {
    @Resource
    private PmsPassService passService;
    @Resource
    private JmsCompanyService companyService;

    /**
     * 查看简历通过人员名单
     * @param queryPageBean
     * @return
     */
    @RequestMapping("/findPassPeople")
    @ApiOperation("查看简历通过人员名单")
    public ResultData<PageResult<PassParam>> findPassPeople(@RequestBody QueryPageBean queryPageBean, Principal principal){
        //通过认证主体，获取公司账号。
        String username = principal.getName();

        //调用服务层，根据公司名称获取公司信息
        JmsCompany company =  companyService.findByUsername(username);

        //封装公司ID进行查询条件
        Map<String,Object> queryParams = queryPageBean.getQueryParams();
        queryParams.put("companyId",company.getId());
        queryPageBean.setQueryParams(queryParams);

        //调用服务层，查看简历通过人员名单
        PageResult<PassParam> pageResult =  passService.findPassPeople(queryPageBean);

        //返回结果对象
        return ResultData.success(Const.QUERY_PASS_PEOPLE_SUCCESS,pageResult);


    }

    /**
     * 修改面试状态为已发邮件告知
     */
    @GetMapping("/updateStatus/{id}")
    @ApiOperation("修改面试状态为已发邮件告知")
    public ResultData<String> updateStatus(@PathVariable(name = "id")Long id) {
        //获取面试ID

        //调用服务层，修改面试名单人员状态为已经发送邮件提醒。
        PmsPass tbPass = passService.getById(id);
        tbPass.setStatus(Const.GET_STUDENT_EMAIL);
        passService.updateById(tbPass);
        //返回结果对象
        return ResultData.success(Const.UPDATE_PASS_STATUS_SUCCESS);
    }

}

